package cn.itcast.bos.web.action.base;

import cn.itcast.bos.domain.base.TakeTime;
import cn.itcast.bos.service.base.TakeTimeService;
import cn.itcast.bos.web.action.common.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

@Namespace("/")
@ParentPackage("json-default")
@Controller
@Scope("prototype")
public class TakeTimeAction extends BaseAction<TakeTime> {

    @Autowired
    //注入service
    private TakeTimeService takeTimeService;

    //添加takeTime
    @Action(value = "takeTime_add",results = {@Result(name = "success",location = "./pages/base/take_time.html",type = "redirect"),
            @Result(name = "input",location = "/index.html",type = "redirect")})
    public String takeTime_add(){
        takeTimeService.save(model);
        return SUCCESS;
    }



    @Action(value = "taketime_findAll",results = {@Result(name = "success",type = "json"),
                @Result(name = "input",location = "/index.html",type = "redirect")})
    public String takeTime_findAll(){


        List<TakeTime> pageData = (List<TakeTime>) takeTimeService.findAll();
        ActionContext.getContext().getValueStack().push(pageData);
        return SUCCESS;
    }

    //作废操作

    private String ids;

    public String getIds() {
        return ids;
    }

    public void setIds(String ids) {
        this.ids = ids;
    }

    @Action(value = "takeTime_delBatch",results = {@Result(name = SUCCESS,location = "./pages/base/take_time.html",type = "redirect"),
            @Result(name = "input",location = "./index.html",type = "redirect")})
    public String takeTimeDelBatch(){
        String[] idArray = ids.split(",");
        takeTimeService.delBatch(idArray);
        return SUCCESS;
    }

    @Action(value = "takeTime_restoreBatch",results = {@Result(name = SUCCESS,location = "./pages/base/take_time.html",type = "redirect"),
            @Result(name = "input",location = "./index.html",type = "redirect")})
    public String takeTimeRestoreBatch(){

        String[] idArray = ids.split(",");
        System.out.println(idArray);
        takeTimeService.restoreBatch(idArray);
        return SUCCESS;
    }
}
